package cn.usian.controller;


import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.jws.WebParam;

@RestController
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmpService empService;


    @GetMapping("findPage")
    public Page findPage(String name, @RequestParam(required = true,defaultValue = "1")Integer pageNum){
        Page<Emp> page = empService.findPage(name,pageNum);
        return page;
    }

    @PostMapping("add")
    public void add(@RequestBody Emp emp){
        empService.add(emp);
    }

    @GetMapping("del")
    public String del(int id){
        empService.del(id);
        return "redirect:findPage";
    }

    @PostMapping("edit")
    public void edit(@RequestBody Emp emp){
        empService.edit(emp);
    }

    @RequestMapping("findById")
    public Emp findById(int id){
        return empService.findById(id);
    }
}
